import Vue from "vue";
import Vuex from "vuex";

Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    list: [],
    //列表数据
    status: 0,
    //保存 当前是全部还是未完全 已完成
    copylist: [],
    //备份一份数据 为了筛选
  },
  getters: {
    num(state) {
      let num1 = 0;
      let num2 = 0;
      state.list.forEach((i) => {
        if (i.status == 1) {
          num1++;
        }
        if (i.status == 2) {
          num2++;
        }
      });
      return { num1, num2 };
    },
    //计算数量
  },
  mutations: {
    setData(state, val) {
      state.list = val;
      state.copylist = val;
      //进入页面请求的数据 给list 一份 给备份也一份
    },
    change(state, i) {
      state.status = i;
    },
    //点击全部 未完成 已完的切换
    filterData(state, num) {
      if (num == "") {
        state.list = state.copylist;
      } else {
        state.list = state.copylist.filter((i) => i.limit <= num);
        //每次都从备份的数据上筛选
      }
    },
    //点击确定过滤数据 要注意每次都从备份的完整的数据上筛选
  },
  actions: {},
  modules: {},
});
